home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / tagsgen.exe / CRCSET.DOC < prev    next >
Text File  |  1991-07-13  |  35KB  |  1,070 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.                               CRCSET version 1.31
  29.                        Copyright (c) 1991 by Kevin Dean
  30.  
  31.                                   Kevin Dean
  32.                          Fairview Mall P.O. Box 55074
  33.                            1800 Sheppard Avenue East
  34.                               Willowdale, Ontario
  35.                                CANADA    M2J 5B9
  36.                            CompuServe ID: 76336,3114
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.                                    Contents
  62.                                    --------
  63.  
  64.                    Warranty ............................  1
  65.  
  66.                    License .............................  2
  67.  
  68.                    Introduction ........................  3
  69.  
  70.                    What is a CRC? ......................  4
  71.  
  72.                    How CRCSET Works ....................  8
  73.  
  74.                    How to Use CRCSET ................... 13
  75.  
  76.                    Vulnerability ....................... 16
  77.  
  78.  
  79.                                    Warranty
  80.  
  81.         The author of CRCSET (hereafter referred to as "the author") makes no
  82. warranty of any kind, expressed or implied, including without limitation, any
  83. warranties of merchantability and/or fitness for a particular purpose.  The
  84. author shall not be liable for any damages, whether direct, indirect, special,
  85. or consequential arising from a failure of this program to operate in the
  86. manner desired by the user.  The author shall not be liable for any damage to
  87. data or property which may be caused directly or indirectly by use of the
  88. program.
  89.  
  90.         In no event will the author be liable to the user for any damages,
  91. including any lost profits, lost savings, or other incidental or consequential
  92. damages arising out of the use or inability to use the program, or for any
  93. claim by any other party.
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.                                   - Page 1 - 
  139.  
  140.  
  141.                                     License
  142.  
  143.         This program is public domain.  As such, it may be freely distributed
  144. by anyone by any means.  No person or organization may charge for this program
  145. except for a minimal charge to cover handling and distribution.
  146.  
  147.         Having said that, I would also like to add that this algorithm has
  148. taken a lot of time and work to develop.  If you like this program, send me a
  149. postcard and let me know.  I would also be interested in copies of your own
  150. programs if you feel that that is appropriate.
  151.  
  152.         Also, if you have any questions or would like to see some more
  153. features in the program, drop me a note by surface or electronic mail (my
  154. address is on the first page of this file).  I will answer all mail regarding
  155. this program.
  156.  
  157.         Customization is available.
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.                                   - Page 2 - 
  201.  
  202.  
  203.                                  Introduction
  204.  
  205.         CRCSET is an anti-virus utility.  Its purpose is to protect programs
  206. (in which supporting code is linked) with one of the most effective weapons
  207. against computer viruses: the Cyclic Redundancy Check, or CRC.  A full
  208. understanding of the CRC is not required to use this utility; if you like, you
  209. can skip over the discussion of the CRC to the section entitled "How to Use
  210. CRCSET".
  211.  
  212.         There are many utilities that perform CRC checks on other programs
  213. (VALIDATE.COM by McAfee associates is one) but most of these are external
  214. programs that are usually run only once, if at all.  The CRC generated by
  215. these utilities must be compared to a value in an external file; if the values
  216. match, the program is not infected.
  217.  
  218.         This approach has two problems: the first is that the CRC check is
  219. run only once when the user gets the program, if at all.  Most people would
  220. never run the check a second time.  The second problem is that the CRC is
  221. stored in an external file (e.g. the documentation).  If someone wants to tack
  222. a virus onto the program, it becomes a simple matter to run the validation
  223. program, copy the CRC values to the documentation, and distribute the infected
  224. program.  Anyone running the validation program would find the same CRC in the
  225. program as in the documentation, and in comes the virus.
  226.  
  227.         Another (increasingly popular) approach is for the CRC to be stored in
  228. the program itself (the .EXE file) and for the program to do its own check
  229. every time it is loaded.  This method is much more effective than the previous
  230. one because it means that the moment the program is infected and the CRC
  231. changes, the infection will be detected the next time the program is run.
  232.  
  233.         There is a potential problem with this method, but before I get into
  234. that, we need some background.
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.                                   - Page 3 - 
  263.  
  264.  
  265.                                 What is a CRC?
  266.  
  267.         The CRC, or Cyclic Redundancy Check, is an error-checking algorithm
  268. used in many types of computer operations, especially in data transfer.  For
  269. example, whenever your computer writes to disk, the disk controller calculates
  270. the CRC of the data being written and writes it with the data.  If your disk
  271. should somehow become corrupted, the CRC check will fail when you next try to
  272. read the data and the disk controller will return with an error, forcing DOS
  273. to display the critical error "Data error reading drive C:".  Most file
  274. transfer protocols (like Xmodem, Zmodem, and some derivatives of Kermit) also
  275. use a CRC check to validate the data being transmitted; if the CRC transmitted
  276. with the data does not match the CRC calculated by the receiving program, then
  277. the transmission has failed and the sending program is asked to retry the
  278. transmission.
  279.  
  280.         The actual calculation of the CRC is very simple.  The algorithm
  281. consists of two parts, a CRC polynomial and a CRC register, and is really an
  282. exercise in modulo-2 arithmetic.  The rules for modulo-2 arithmetic are shown
  283. in the following table:
  284.  
  285.                                    0 + 0 = 0
  286.                                    0 + 1 = 1
  287.                                    1 + 0 = 1
  288.                                    1 + 1 = 0
  289.  
  290. For those of you familiar with binary logic, these rules are equivalent to
  291. the exclusive-or operation.  Note: under modulo-2 arithmetic, subtraction is
  292. equivalent to addition.
  293.  
  294.         There is nothing magical about modulo-2 arithmetic and it has no
  295. special properties that make it better suited to CRC calculations than
  296. standard arithmetic; rather, since modulo-2 arithmetic doesn't carry from one
  297. column to the next (i.e. 1 + 1 = 0 with no carry), it's just easier to
  298. implement in hardware and software than any other method.  Consider the
  299. following:
  300.  
  301. 1. Binary addition, normal rules of carry
  302.      101101001
  303.    + 110110111
  304.    -----------
  305.     1100100000
  306.  
  307. 2. Binary addition, modulo-2 arithmetic (no carry)
  308.      101101001
  309.    + 110110111
  310.    -----------
  311.      011011110
  312.  
  313. The first addition requires us to carry any overflow from right to left.  The
  314. second addition requires no carry operations and can be performed much faster
  315. both by humans and by computers.
  316.  
  317.         The CRC algorithm can best be illustrated by the following diagram of
  318. a 4-bit CRC generator:
  319.  
  320.  
  321.  
  322.  
  323.  
  324.                                   - Page 4 - 
  325.  
  326.  
  327.                                  CRC polynomial
  328.                ------------1-----------0-----------1-----------1
  329.                |     3     |     2           1     |     0     |
  330.                |   -----   v   -----       -----   v   -----   v
  331.                + <-| x |<- + <-| x |<------| x |<- + <-| x |<- +
  332.                ^   -----       -----       -----       -----
  333.                |                  CRC register
  334.                ---- binary data stream
  335.  
  336. Each '+' symbol represents modulo-2 addition.  The numbers above the CRC
  337. register are the bit numbers of the register.
  338.  
  339.         The CRC is calculated as follows:
  340.  
  341. 1. Initiali